package com.example;


import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MenuCodeConvert {

    /**
     * code 为36进制 String
     * 1fd4 返回 [16,10,3]
     *
     * @param code
     * @return
     */
    public static List<Long> codeToIds(String code) {
        List<Long> ids = new ArrayList<>();
        BigInteger bigInteger = new BigInteger(code, 36);
        for (int i = 0; i < bigInteger.bitLength(); i++) {
            if (bigInteger.testBit(i)) {
                ids.add((long) i);
            }
        }
        return ids;
    }

    /**
     * [16,10,3]  编码 1fd4
     *
     * @param ids
     * @return
     */
    public static String idsToCode(List<Long> ids) {
        if (ids == null && ids.size() == 0) {
            return null;
        }
        BigInteger bigInteger = BigInteger.ZERO;
        for (Long id : ids) {
            bigInteger = bigInteger.setBit(id.intValue());
        }
        return bigInteger.toString(36);
    }

    public static void main(String[] args) {
        List<Long> ids = Arrays.asList(1000L );
        System.out.println(idsToCode(ids));

    }

}
